<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-position="left" v-show="showSearch">
      <el-form-item label="商户号" prop="memberId">
        <el-input
          v-model="queryParams.memberId"
          placeholder="请输入商户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户订单号" prop="memberOrderNo">
        <el-input
          v-model="queryParams.memberOrderNo"
          placeholder="请输入商户订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="系统订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入系统订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上游订单号" prop="upOrderNo">
        <el-input
          v-model="queryParams.upOrderNo"
          placeholder="请输入上游订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="queryParams.orderType" placeholder="订单类型" size="small" :clearable="true">
            <el-option
              v-for="dict in dict.type.aipay_order_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
          <el-select v-model="queryParams.orderStatus" placeholder="订单状态" size="small" :clearable="true">
            <el-option
              v-for="dict in dict.type.aipay_order_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
      </el-form-item>
      <el-form-item label="通知状态" prop="notifyStatus">
          <el-select v-model="queryParams.notifyStatus" placeholder="通知状态" size="small" :clearable="true">
            <el-option
              v-for="dict in dict.type.aipay_order_notify_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" v-hasPermi="['aipay:order:remove']">删除未支付订单(一天以前)</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['aipay:order:list']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="商户号" align="center" prop="memberId" />
      <el-table-column label="商户订单号" align="center" prop="memberOrderNo" width="180"/>
      <el-table-column label="系统订单号" align="center" prop="orderNo" width="180"/>
      <el-table-column label="上游订单号" align="center" prop="upOrderNo" width="180"/>
      <el-table-column label="订单金额" align="center" prop="amount" />
      <el-table-column label="获得金额" align="center" prop="earnAmount" />
      <el-table-column label="上游金额" align="center" prop="upAmount" />
      <el-table-column label="订单类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aipay_order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aipay_order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="通知状态" align="center" prop="notifyStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aipay_order_notify_status" :value="scope.row.notifyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="通知次数" align="center" prop="notifyCount" />
      <el-table-column label="接口类型" align="center" prop="payTypeName" width="130"/>
      <el-table-column label="接口上游" align="center" prop="upParamsName" width="130"/>
      <el-table-column label="接口账户" align="center" prop="payAccountName" width="130"/>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否补单" align="center" prop="supplementStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aipay_order_supplement_status" :value="scope.row.supplementStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="ip地址" align="center" prop="ip" />
      <el-table-column label="添加时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleView(scope.row)"
            v-hasPermi="['aipay:order:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['aipay:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" :close-on-click-modal="false" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="商户号" prop="memberId">{{form.memberId}}</el-form-item>
        <el-form-item label="商户订单号" prop="memberOrderNo">{{form.memberOrderNo}}</el-form-item>
        <el-form-item label="系统订单号" prop="memberOrderNo">{{form.orderNo}}</el-form-item>
        <el-form-item label="上游订单号" prop="memberOrderNo">{{form.upOrderNo}}</el-form-item>
        <el-form-item label="订单类型" prop="memberOrderNo">
          <dict-tag :options="dict.type.aipay_order_type" :value="form.orderType"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="orderStatus">
          <dict-tag :options="dict.type.aipay_order_status" :value="form.orderStatus"/>
        </el-form-item>
        <el-form-item label="通知状态" prop="notifyStatus">
          <dict-tag :options="dict.type.aipay_order_notify_status" :value="form.notifyStatus"/>
        </el-form-item>
        <el-form-item label="发起时间" prop="ctime">{{ parseTime(form.ctime) }}</el-form-item>
        <el-form-item label="发起IP" prop="ip">{{form.ip}}</el-form-item>
        <el-form-item label="支付时间" prop="ctime">{{ parseTime(form.payTime) }}</el-form-item>
        <el-form-item label="订单金额" prop="ctime">{{ form.amount }}</el-form-item>
        <el-form-item label="用户获得金额" prop="ctime">{{ form.earnAmount }}</el-form-item>
        <el-form-item label="代理获得金额" prop="ctime">{{ form.upAmount }}</el-form-item>
        <el-form-item label="订单费率" prop="ctime">{{ form.orderFee }}%</el-form-item>
        <el-form-item label="接口费率" prop="ctime">{{ form.apiFee }}%</el-form-item>
        <el-form-item label="接口类型" prop="ctime">{{ form.payTypeName }}</el-form-item>
        <el-form-item label="接口上游" prop="ctime">{{ form.upParamsName }}</el-form-item>
        <el-form-item label="接口账户" prop="ctime">{{ form.payAccountName }}</el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBankCard, getBankCard, addBankCard, updateBankCard, delBankCard  } from "@/api/aipay/bank";
import { listOrder, getOrder, updateOrder, delOrder  } from "@/api/aipay/order";

export default {
  name: "BankCard",
  dicts: ['sys_bool_status', 'aipay_order_type', 'aipay_order_status', 'aipay_order_notify_status', 'aipay_order_supplement_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //表格数据
      postList: [],
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      activeName: "public",
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        orderStatus: undefined,
        memberId: undefined,
        memberOrderNo: undefined,
        orderNo: undefined,
        upOrderNo: undefined,
        notifyStatus: undefined,
        orderType: undefined
      },
      // 表单参数
      form: {
        id: undefined
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
    },
    /** 修改按钮操作 */
    handleView(row) {
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "订单详情";
    },
    /** 提交按钮 */
    submitForm: function() {
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(row.id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    }
    
  }
};
</script>
